<?php

namespace App\Http\Controllers;

use App\Carousel;
use Illuminate\Http\Request;
use MercurySeries\Flashy\Flashy;

class CarouselController extends Controller
{
    public function show()
    {
        $carousels =  Carousel::all();
        return view('carousel.show' ,compact('carousels'));
    }

    public function add()
    {
        return view('carousel.add');
    }

    public function store(Request $request)
    {
        Carousel::create( $request->all() );
        Flashy::success('新增轮播图成功');
        return redirect()->route('carousel.show');
    }

    public function edit(Carousel $carousel)
    {
        return view('carousel.edit',compact('carousel'));
    }

    public function update(Carousel $carousel,Request $request)
    {
        $carousel->update($request->all());
        Flashy::success('修改成功');
        return redirect()->route('carousel.show');
    }

    public function delete(Carousel $carousel)
    {
        $carousel->delete();

        Flashy::success('操作成功');

        return redirect()->back();
    }
}
